package com.myidis.controller;

import com.myidis.entity.*;
import com.myidis.request.SearchReq;
import com.myidis.request.SignalReq;
import com.myidis.servlet.SignalQuotaManagementServlet;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

@Controller
@Api(tags = "信号灯/综合景气指数 指标管理接口")
@RequestMapping("/SignalQuotaManagement")
public class SignalQuotaManagementController {
    @Autowired
    SignalQuotaManagementServlet signalQuotaManagementServlet;

    @ResponseBody
    @RequestMapping("/findSubject")
    @ApiOperation("返回现有主题列表")
    public ArrayList<AnalysisTheme> findSubject() {
        return signalQuotaManagementServlet.findSubject();
    }

    @ResponseBody
    @RequestMapping("/subjectQuotaList")
    @ApiOperation("返回主题下的备选指标")
    public ArrayList<SignalQuota> subjectQuotaList(@RequestBody SearchReq sea) {
        String subject = sea.getCondition();
        return signalQuotaManagementServlet.subjectQuotaList(subject);
    }

    @ResponseBody
    @RequestMapping("/combination")
    @ApiOperation("返回指标组合列表")
    public ArrayList<IndexCombination> combination() {
        return signalQuotaManagementServlet.combination();
    }

    @ResponseBody
    @RequestMapping("/combinationQuotaList")
    @ApiOperation("返回组合下的备选指标")
    public ArrayList<SignalQuota> combinationQuotaList(@RequestBody SearchReq sea) {
        String combination = sea.getCondition();
        return signalQuotaManagementServlet.combinationQuotaList(combination);
    }

    @ResponseBody
    @RequestMapping("/delectInSubject")
    @ApiOperation("删除主题下的一个指标")
    public int delectInSubject(@RequestBody Quota del) {
        int id = del.getId();
        return signalQuotaManagementServlet.delectInSubject(id);
    }

    @ResponseBody
    @RequestMapping("/delectInCombination")
    @ApiOperation("删除组合内的一个指标")
    public int delectInCombination(@RequestBody Quota del) {
        int id = del.getId();
        return signalQuotaManagementServlet.delectInCombination(id);
    }

    @ResponseBody
    @RequestMapping("/delectCombination")
    @ApiOperation("删除一个指标组合")
    public int delectCombination(@RequestBody Quota del) {
        int id = del.getId();
        return signalQuotaManagementServlet.delectCombination(id);
    }

    @ResponseBody
    @RequestMapping("/addCombination")
    @ApiOperation("增加一个指标组合")
    public int addCombination(@RequestBody IndexCombination add){
        return signalQuotaManagementServlet.addCombination(add);
    }

    @ResponseBody
    @RequestMapping("/addToSubject")
    @ApiOperation("为当前主题增加一个备选指标")
    public int addToSubject(@RequestBody SignalQuota add){
        return signalQuotaManagementServlet.addToSubject(add);
    }

    @ResponseBody
    @RequestMapping("/addToCombination")
    @ApiOperation("为当前组合增加一个指标")
    public int addToCombination(@RequestBody SignalQuota add){
        return signalQuotaManagementServlet.addToCombination(add);
    }

    /*
    sea.keyWord1 -> subject
    sea.keyWord2 -> quota
     */
    @ResponseBody
    @RequestMapping("/detail")
    @ApiOperation("指标详细信息")
    public SignalThreshold detail(@RequestBody SearchReq sea){
        return signalQuotaManagementServlet.detail(sea);
    }


    @ResponseBody
    @RequestMapping("/calculateThreshold")
    @ApiOperation("计算阈值")
    public SignalThreshold calculateThreshold(@RequestBody SignalReq sea){
        return signalQuotaManagementServlet.calculateThreshold(sea);
    }

    @ResponseBody
    @RequestMapping("/saveThreshold")
    @ApiOperation("保存阈值")
    public int saveThreshold(@RequestBody SignalThreshold signalThreshold){
        return signalQuotaManagementServlet.saveThreshold(signalThreshold);
    }
}
